package top.younote.cherry.controller;

import com.alibaba.fastjson.JSON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import top.younote.cherry.model.bo.WechatCalenderCallbackBO;
import top.younote.cherry.utill.aes.AesException;
import top.younote.cherry.utill.aes.WXBizJsonMsgCrypt;

import javax.servlet.http.HttpServletRequest;
import java.util.stream.Stream;

/**
 * @Description:
 * @Author: duanyu
 * @CreateTime: 2021-12-19 20:14
 **/
@RestController
public class CalenderController {
    @Autowired
    private ApplicationContext context;

    @GetMapping("/calender/callback")
    public String calenderCallback(WechatCalenderCallbackBO request) throws AesException {
        WXBizJsonMsgCrypt wxBizJsonMsgCrypt = new WXBizJsonMsgCrypt("pQIG2z",
                "83jQW2P3Aj38kmI7MRLpsFyjNyiynvLMQI9VgK141iF",
                "wwaeb7ac3aa1b48984");
        return wxBizJsonMsgCrypt.VerifyURL(request.getMsg_signature(), request.getTimestamp(), request.getNonce(), request.getEchostr());
    }

    @PostMapping("/calender/callback")
    public String calenderCallbackPost(@RequestBody String body, HttpServletRequest request) throws AesException {
        WechatCalenderCallbackBO param = new WechatCalenderCallbackBO();
        param.setMsg_signature(request.getParameter("msg_signature"));
        param.setTimestamp(request.getParameter("timestamp"));
        param.setNonce(request.getParameter("nonce"));
        param.setEchostr(request.getParameter("echostr"));
        System.out.println(body);
        return null;
    }

    public static void main(String[] args) {
        int count = Stream.of(1,2,3).reduce(0, Integer::sum);
        System.out.println(count);
    }
}
